Public Function HexToDec(ByVal strHexVal As String) As Double
    'This function will take a hexidecimal value in string
    'format and return the decimal value also in string format.
    'It does NOT account for signed numbers or decimal points.
    
    Dim intCounter As Integer
    Dim dblDecVal As Double
    Dim bytCharNum As Byte
    Dim strTempChar As String * 1
    
    'remove spaces
    strHexVal = Trim(strHexVal)
    
    'if a null string was passed then exit
    If strHexVal = "" Then
        'return a zero value
        HexToDec = "0"
    End If
    
    'change all letters to uppercase
    strHexVal = UCase(strHexVal)
    
    'if the number to be converted is larger than 7 characters, then
    'exit the function
    If Len(strHexVal) > 7 Then
        'return maximum value and exit
        HexToDec = (2 ^ 31) - 1
        Exit Function
    End If
    
    'convert the numbers to decimal
    For intCounter = Len(strHexVal) To 1 Step -1
        'first get the hexidecimal digit
        strTempChar = Mid(strHexVal, intCounter, 1)
        
        'convert the character to a number
        Select Case strTempChar
        Case "A" To "F"
            'the ascii characters for "A" to "F" start at 65
            'add ten to convert the hex digit to decimal value
            bytCharNum = 10 + (Asc(strTempChar) - 65)
        Case "0" To "9"
            'the ascii characters for "0" to "9" start and 48
            bytCharNum = Asc(strTempChar) - 48
        Case Else
            'any other character is assumed to be zero
            bytCharNum = 0
        End Select
        
        'add the decimal value of the current hex digit, accounting for
        'it hexidecimal "power", eg the second digit will be multiplied by
        '16 to get the decimal value and added to the total.
        dblDecVal = dblDecVal + (bytCharNum * (16 ^ (Len(strHexVal) - intCounter)))
    Next intCounter
    
    'return the value
    HexToDec = dblDecVal
End Function
